package com.itheima.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect //AOP类
public class AspectDemo1 {
//   前置通知
    @Before("execution(* com.itheima.service.*.*(..))")
    public void before() {
        log.info("前置通知....");
    }

//    最终通知(方法里面不管报不报错都会通知)
    @After("execution(* com.itheima.service.*.*(..))")
    public void after(){
        log.info("最终通知....");

    }

//    环绕通知
    @Around("execution(* com.itheima.service.*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        log.info("前置通知....");
        Object result = pjp.proceed();
        log.info("后置通知....");
        return result;
    }

//    异常通知
    @AfterThrowing("execution(* com.itheima.service.*.*(..))")
    public void afterThrowing(){
        log.info("异常通知....");

    }

//    后置通知(方法如果有异常,则不会通知)
    @AfterReturning("execution(* com.itheima.service.*.*(..))")
    public void afterReturning(){
        log.info("后置通知2....");

    }


}
